﻿using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using DAL.Configuration;

namespace DAL
{
    public class ImsContext : DbContext
    {
        /// <summary>
        /// Gets or sets the products.
        /// </summary>
        /// <value>
        /// The products.
        /// </value>
        public DbSet<BO.Product> Products { get; set; }

        /// <summary>
        /// Gets or sets the categories.
        /// </summary>
        /// <value>
        /// The categories.
        /// </value>
        public DbSet<BO.Category> Categories { get; set; }

        /// <summary>
        /// Gets the ims database.
        /// </summary>
        public Database ImsDatabase
        {
            get { return this.Database; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ImsContext"/> class.
        /// </summary>
        /// <param name="connectionString">The connection string.</param>
        /*  public ImsContext(string connectionString)
              : base(connectionString)
          {
              Database.SetInitializer<ImsContext>(null);
          }*/

        /// <summary>
        /// Called when [model creating].
        /// </summary>
        /// <param name="modelBuilder">The model builder.</param>
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // remove pluralisation
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            // Product : Configuration
            modelBuilder.Configurations.Add(new ProductConfiguration());
        }
    }
}